package com.jackykeke.opengldemo.renderer;

import android.graphics.Color;
import android.opengl.GLES30;
import android.opengl.GLSurfaceView;

import androidx.annotation.ColorInt;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class ColorRenderer implements GLSurfaceView.Renderer {

    private @ColorInt
    int color;
    int colorUnit = 255;


    public ColorRenderer(@ColorInt int color) {
        this.color = color;
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        //设置背景颜色
        float redF = (float) Color.red(color) / colorUnit;
        float greenF = (float) Color.green(color) / colorUnit;
        float blueF = (float) Color.blue(color) / colorUnit;
        float alphaF = (float) Color.alpha(color) / colorUnit;

        GLES30.glClearColor(redF,greenF,blueF,alphaF);
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {

        //设置视图窗口
        GLES30.glViewport(0,0,width,height);

    }

    @Override
    public void onDrawFrame(GL10 gl) {
        GLES30.glClear(GL10.GL_COLOR_BUFFER_BIT);
    }
}
